Skip to content

fix(truapi): retry native preimage lookups after a miss - #1673

Merged
Mikelle merged 11 commits into
mainfrom
fix/native-preimage-lookup-retry
Oct 26, 2026
Merged

Mikelle merged 11 commits into
mainfrom
fix/native-preimage-lookup-retry

Conversation

@Mikelle

@Mikelle Mikelle commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #1219

On iOS and Android, a preimage lookup whose first fetch failed never got the value. After the first answer the native shim only forwarded notifyPreimageChanged, and neither app calls it.

After a miss, CallbackPlatform::lookup_preimage asks the app again every 6 s for the first 30 s, which covers the product SDK's lookup timeouts, then every 30 s. It stops when the app returns bytes that hash to the key, returns an error, or the product unsubscribes. Keys that are not 32 bytes are not retried. The apps need no changes.

Tested with cargo test -p truapi (new tests in native/tests.rs).

The native shim sent the app's first lookup_preimage answer and then
waited for notifyPreimageChanged, which neither the iOS nor the Android
app calls. Both apps answer a failed fetch with a miss, so a lookup whose
first fetch failed never resolved.

After a miss, the shim calls lookup_preimage again, 6 seconds apart and
backing off to 30, until it gets bytes that hash to the key. An app error
ends the retries and reaches the product. Keys that are not 32 bytes are
not retried.

Fixes #1219
…onds

The product SDK's lookup helpers wait 20 seconds (NFT artwork) and 30
seconds (cloud storage) before giving up. Doubling the pause from 6
seconds retried only twice in that time, at 6 and 18 seconds.

The native lookup now retries every 6 seconds for the first five retries,
then every 30 seconds. That gives three retries within 20 seconds and five
within 30, and keeps lookups a product holds open at one request every
30 seconds.
A product dials the bridge and opens preimage_lookup_subscribe, so the
frames go through dispatch, the runtime's hash check and the native
retry. The tests check that a lookup whose first fetch failed gets the
value once the host has it, that bytes which do not hash to the key never
reach the product, and that a Stop frame or a closed connection ends the
retries.
@Mikelle
Mikelle requested a review from a team October 23, 2026 17:28
@github-actions github-actions Bot added the area:core Touches the Rust core under rust/crates label Oct 23, 2026
@Mikelle Mikelle self-assigned this Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

CI Status: 25 required jobs green, 22 passed and 3 skipped by path filter.

All job results
job result
android-bindings success
bundle-size success
changes success
changeset-guard success
cli-package success
codegen success
e2e skipped
explorer success
headless-install success
host-android-bindings success
host-android-detekt success
host-wasm success
ios-bindings success
ios-swift success
licenses success
playground success
provider-android-bindings skipped
release-guard success
rust success
ts-client success
ts-debugger success
ts-host success
ts-trinity-stack success
wasm-provider success
workflow-lint skipped

Signing credentials: valid as of 2026-10-26

Commit 9fdd4922 · run log

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Bundle size report

Compared with main at afc8594.

Raw Gzip Brotli
truapi-host 8.07 MiB (+59 B) 5.72 MiB (+289 B) 5.43 MiB (+154 B)
truapi-provider 4.03 MiB 1.27 MiB 960.2 KiB
truapi 6.72 MiB 950.2 KiB 776.8 KiB
trinity-stack 562.4 KiB 225.5 KiB 186.6 KiB
Total 19.37 MiB (+59 B) 8.14 MiB (+289 B) 7.31 MiB (+154 B)

WebAssembly modules

Raw Gzip Brotli
truapi-host/wasm/web/truapi_server_bg.wasm 2.96 MiB (+59 B) 1.03 MiB (+289 B) 789.1 KiB (+158 B)
truapi-host/wasm/web/truapi_verifiable_bg.wasm 4.89 MiB 4.64 MiB 4.61 MiB
truapi-provider/truapi_provider_bg.wasm 3.99 MiB 1.26 MiB 952.5 KiB
trinity-stack/wasm/trinity_stack_bg.wasm 525.1 KiB 217.1 KiB 179.3 KiB
Changed files (1)
Raw Gzip Brotli
truapi-host/wasm/web/truapi_server_bg.wasm 2.96 MiB (+59 B) 1.03 MiB (+289 B) 789.1 KiB (+158 B)

Commit: 9fdd492

@pgherveou pgherveou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve to unblock - with some comments

The retry decision matched on the GenericError the host error had already
been turned into. It now matches on HostRejection, so a new variant would
force a decision, and the conversion to GenericError happens once where
the stream is assembled.
A preimage key is a blake2b-256 digest, but PreimageHost took a Vec<u8>,
so the native shim and the CLI each checked the length. The runtime now
answers a key of any other length with a miss itself, and every platform
gets a [u8; 32]. The native callback and the JS host callback still take
bytes, so apps and dotli need no change.
…ookup-retry

# Conflicts:
#	rust/crates/truapi/src/native/platform.rs
@Mikelle
Mikelle enabled auto-merge October 26, 2026 10:33
@Mikelle
Mikelle added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit dce190f Oct 26, 2026
49 checks passed
@Mikelle
Mikelle deleted the fix/native-preimage-lookup-retry branch October 26, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Touches the Rust core under rust/crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android/iOS: a preimage lookup whose first fetch fails never delivers the value

2 participants